package com.zzsong.proxy.proxy;

import com.zzsong.proxy.service.DogService;
import com.zzsong.proxy.service.impl.DogServiceImpl;

import java.lang.reflect.Proxy;

public class DynamicDemo {

    public static void main(String[] args){
        DogService dogService = new DogServiceImpl();
        DynamicProxy dynamicProxy = new DynamicProxy(dogService);
        ClassLoader loader = dogService.getClass().getClassLoader();// 获取被代理类的ClassLoader
        // 动态构造一个代理对象
        DogService dogService1 = (DogService) Proxy.newProxyInstance(loader,new Class[]{DogService.class},dynamicProxy);
        dogService1.yell();
        }
}
